package node;

import lexer.LexType;
import parser.Parser;

import java.io.IOException;

public class UnaryOpNode extends ASTNode {
    public final String name = "<UnaryOp>";
    // UnaryOp → '+' | '−' | '!'
    private final char unaryOp;

    public UnaryOpNode(char unaryOp) {
        this.unaryOp = unaryOp;
    }

    public char getUnaryOp() {
        return unaryOp;
    }

    @Override
    public void show() throws IOException {
        if (unaryOp == '+') {
            Parser.parserWriter.write(LexType.PLUS + " " + "+" + "\n");
        } else if (unaryOp == '-') {
            Parser.parserWriter.write(LexType.MINU + " " + "-" + "\n");
        } else if (unaryOp == '!') {
            Parser.parserWriter.write(LexType.NOT + " " + "!" + "\n");
        }
        Parser.parserWriter.write(name + "\n");
    }

}
